// Problem 053: Combinatoric selections
// There are exactly ten ways of selecting three from five, 12345:
// 123, 124, 125, 134, 135, 145, 234, 235, 245, and 345
// It is not until n=23, that a value C(23,10)=1144066 exceeds one-million:
// How many, not necessarily distinct, values of C(n,r) for 1<=n<=100, are greater than one-million?

package main

import (
	"fmt"
	"math/big"
)

func p053() {
	ans := 0
	var n, r int64
	var bn, br big.Int
	bz := big.NewInt(0)
	om := big.NewInt(1000000)
	for n = 23; n <= 100; n++ {
		flag := false
		for r = n / 2; r > 1; r-- {
			bn.SetInt64(n)
			br.SetInt64(r)
			bz.Binomial(n, r)
			if bz.Cmp(om) == 1 {
				flag = true
				ans += 2
			} else {
				break
			}
		}
		if flag && n%2 == 0 {
			ans--
		}
	}
	fmt.Println("Prolem 053:", ans)
}
